<?php
class dwYY{
	public $_url = 'http://webapi.duowan.com/api_yy.php';
	
	/**
	*功能： 发送YY系统消息
	*用法： obj('dwSMS')->sendSysMsg('uid', '可包含html代码的内容');
	*接口返回json数据 : 若code为1是成功，否则为失败
	*/
	public function sendSysMsg($uid, $msg, $title='温馨提示', $button_text='关闭', $button_action=''){			
		$data['act'] = 'sendSysMsg';
		$data['uid'] = $uid;
		$data['msg'] = $msg;
		$data['title'] = $title;
		$data['button_text'] = $button_text;
		$data['button_action'] = $button_action;
		
		return $this->curlPost($this->_url, $data);
	}

	/**
	*功能： YY发送群通知消息
	*用法： obj('dwSMS')->sendGroupMsg('test', '测试');
	*接口返回json数据 : 若code为1是成功，否则为失败
	*/
	public function sendGroupMsg($group, $msg, $nick='系统通知'){			
		$data['act'] = 'sendGroupMsg';
		$data['group'] = $group;
		$data['msg'] = $msg;
		$data['nick'] = $nick;
		
		return $this->curlPost($this->_url, $data);
	}
	
	//通过curl post数据
	protected function curlPost($url, $data = array()) {
		$c = curl_init(); 
		curl_setopt($c, CURLOPT_RETURNTRANSFER, true); 
		curl_setopt($c, CURLOPT_URL, $url); 
		curl_setopt($c, CURLOPT_POST, true); 
		curl_setopt($c, CURLOPT_TIMEOUT, 5); 
		curl_setopt($c, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);	
		curl_setopt($c, CURLOPT_POSTFIELDS, http_build_query($data)); 	
		$ret = curl_exec($c); 
		curl_close($c); 
		return $ret;
	}
}
